package com.rainsoft.center.isec.frame.handler;

import com.rainsoft.center.isec.stream.library.entity.hbase.BaseLibEntity;
import org.apache.spark.sql.Dataset;

/**
 * @Name com.rainsoft.center.isec.frame.handler.ADatasetHandler
 * @Description
 * @Author Elwyn
 * @Version 2017/12/8
 * @Copyright 上海云辰信息科技有限公司
 **/
public abstract class ADatasetHandler<T extends BaseLibEntity> {
	private String tableName;
	private ADatasetHandler<T> next;

	public ADatasetHandler(String tableName) {
		this.tableName = tableName;
	}

	public ADatasetHandler setNext(ADatasetHandler<T> next) {
		this.next = next;
		return next;
	}

	public final void support(Dataset<T> dataset) {
		if (resolve(dataset)) {
			done(dataset);
		} else if (next != null) {
			next.support(dataset);
		} else {
			fail(dataset);
		}
	}


	protected abstract boolean resolve(Dataset<T> javaRDD);

	protected void done(Dataset<T> javaRDD) {
		System.out.println(javaRDD + " is resolved by " + this.getClass().getSimpleName());
	}

	protected void fail(Dataset<T> javaRDD) {
		System.out.println(javaRDD + " cannot ben resolved ");
	}
}
